var path = require('path');
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
    entry: {
        index: './front/js/index.js',
        admin: './front/js/admin.js',
        login: './front/js/login.js'
    },
    output: {
        path: path.resolve(__dirname, 'www/static'),
        publicPath: '/static/',
        chunkFilename: 'js/[id].js',
        filename: 'js/[name].build.js'
    },
    resolve: {
        root: path.join(__dirname, 'node_modules'),
        extensions: ['', '.js', '.vue', '.css', '.less']
    },
    resolveLoader: {    // Like resolve but for loaders.
        root: path.join(__dirname, 'node_modules'),
    },
    module: {
        loaders: [
            {
                test: /\.vue$/,
                loader: 'vue'
            },
            {
                test: /\.js$/,
                loader: 'babel',
                exclude: /node_modules/
            },
            {
                test: /\.css$/,
                loader: 'style!css'
            },
            {
                test: /\.less$/,
                loader: 'style!css!less'
            },
            {
                test: /\.(eot|svg|ttf|woff|woff2)(\?\S*)?$/,
                loader: 'file',
                query: {
                    limit: 10000,
                    name: './font/[name].[ext]'
                }
            },
            {
                test: /\.(png|jpg|jpeg|gif)$/,
                loader: 'url',
                query: {
                    limit: 10000,
                    name: './img/[name].[ext]'
                }
            }
        ]
    },
    plugins: [
        // new webpack.optimize.CommonsChunkPlugin('./js/common.js'),   // 提取公共部分，以提供我们浏览器的缓存复用
        new HtmlWebpackPlugin({
            filename: "../../view/home/index_index.html",  // 生成的html存放路径，相对于 path
            template: "./front/view/index.html",   // html模板路径
            title: "<%=_('title')%>",
            inject: false
            // chunks: ['index']   // 根据名称单独引入html中
        }),
        new HtmlWebpackPlugin({
            filename: "../../view/admin/index_index.html",
            template: "./front/view/admin.html",
            title: "<%=_('title')%>",
            inject: false
            // chunks: ['admin']
        }),
        new HtmlWebpackPlugin({
            filename: "../../view/admin/index_login.html",
            template: "./front/view/login.html",
            title: "<%=_('title')%>",
            inject: false
            // chunks: ['admin']
        }),
        // 正式环境使用
        // new webpack.optimize.UglifyJsPlugin({
        //     compress: {
        //         warnings: false
        //     }
        // })
    ],
    devServer: {
        historyApiFallback: true,
        // host: '0.0.0.0', // 统一localhost,为了可以内网手机调试
        port: 8360,
        // noInfo: true
    },
    devtool: '#cheap-module-source-map'
};